<template>
	<view class="detail-page">
		<!-- 自定义导航栏 -->
		<view class="nav-bar" :style="{ paddingTop: statusBarHeight + 'px' }">
			<view class="nav-content">
				<view class="nav-back" @click="goBack">
					<text class="back-icon">‹</text>
				</view>
				<text class="nav-title">个人信息</text>
				<view class="nav-right">
					<text class="nav-icon">⋯</text>
					<text class="nav-icon">○</text>
				</view>
			</view>
		</view>

		<!-- 内容区域 -->
		<view class="content-area">
			<!-- 头像行 -->
			<view class="info-row" @click="changeAvatar">
				<text class="row-label">头像</text>
				<view class="row-right">
					<image :src="avatarUrl" class="avatar-img" mode="aspectFill" />
					<text class="arrow">›</text>
				</view>
			</view>
			<view class="divider"></view>

			<!-- 姓名行 -->
			<view class="info-row">
				<text class="row-label">姓名</text>
				<text class="row-value">{{ userName }}</text>
			</view>
			<view class="divider"></view>

			<!-- 电话行 -->
			<view class="info-row" @click="editPhone">
				<text class="row-label">电话</text>
				<view class="row-right">
					<text class="row-value">{{ phoneNumber }}</text>
					<text class="arrow">›</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		onLoad,
		onShow
	} from '@dcloudio/uni-app';
	import {
		ref
	} from 'vue';

	// 状态栏高度
	const statusBarHeight = ref(0);

	// 用户信息
	const avatarUrl = ref('/static/老人4.png');
	const userName = ref('张先生');
	const phoneNumber = ref('15023457896');

	// 返回上一页
	const goBack = () => {
		uni.navigateBack();
	};

	// 更换头像
	const changeAvatar = () => {
		uni.navigateTo({
			url: '/pages/my/ChangeAvatar?currentAvatar=' + encodeURIComponent(avatarUrl.value)
		});
	};

	// 编辑手机号
	const editPhone = () => {
		uni.navigateTo({
			url: '/pages/my/EditPhone?phone=' + phoneNumber.value
		});
	};

	onLoad(() => {
		// 获取状态栏高度
		const systemInfo = uni.getSystemInfoSync();
		statusBarHeight.value = systemInfo.statusBarHeight;
	});

	onShow(() => {
		// 从修改手机号页面返回时，更新手机号显示
		const updatedPhone = uni.getStorageSync('updatedPhone');
		if (updatedPhone) {
			phoneNumber.value = updatedPhone;
			uni.removeStorageSync('updatedPhone');
		}
		
		// 从修改头像页面返回时，更新头像显示
		const updatedAvatar = uni.getStorageSync('updatedAvatar');
		if (updatedAvatar) {
			avatarUrl.value = updatedAvatar;
			uni.removeStorageSync('updatedAvatar');
		}
	});
</script>

<style scoped>
	.detail-page {
		background-color: #f5f5f5;
		min-height: 100vh;
	}

	/* 导航栏 */
	.nav-bar {
		background-color: #007AFF;
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		z-index: 1000;
	}

	.nav-content {
		height: 44px;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0 30rpx;
	}

	.nav-back {
		width: 60rpx;
		height: 60rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.back-icon {
		color: #fff;
		font-size: 48rpx;
		font-weight: 300;
		line-height: 1;
	}

	.nav-title {
		color: #fff;
		font-size: 36rpx;
		font-weight: 500;
	}

	.nav-right {
		display: flex;
		align-items: center;
		gap: 20rpx;
	}

	.nav-icon {
		color: #fff;
		font-size: 40rpx;
	}

	/* 内容区域 */
	.content-area {
		margin-top: calc(44px + var(--status-bar-height, 0px));
		background-color: #fff;
		border-radius: 20rpx 20rpx 0 0;
		overflow: hidden;
		margin-left: 0;
		margin-right: 0;
	}

	.info-row {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 30rpx;
		min-height: 100rpx;
		box-sizing: border-box;
	}

	.info-row:active {
		background-color: #f5f5f5;
	}

	.row-label {
		font-size: 32rpx;
		color: #333;
	}

	.row-right {
		display: flex;
		align-items: center;
		gap: 20rpx;
	}

	.avatar-img {
		width: 100rpx;
		height: 100rpx;
		border-radius: 50%;
	}

	.row-value {
		font-size: 32rpx;
		color: #333;
	}

	.arrow {
		color: #999;
		font-size: 40rpx;
		font-weight: 300;
		line-height: 1;
	}

	.divider {
		height: 1rpx;
		background-color: #e5e5e5;
		margin-left: 30rpx;
	}
</style>